"""
@author: sumeng
@file: 作业.py
@time: 2023/5/30 17:30
"""
# 1、验证ipv4地址合法性
# 1~255.1~255.1~255.1~255
import re

ip = input("请输入一个ip地址:")
ret = re.findall(r'^((([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]))$', ip)
if ret:
    print("是一个合法的ipv4地址")
else:
    print("不是一个合法的ipv4地址")
# 2、从三创官网上下载所有图片
import re
import requests

url = "https://www.sanchuangedu.cn/"
response = requests.get(url)
html_cont = response.text

image_urls = re.findall(r'<img\s+src=([^"\'>\s]+)', html_cont)

print(image_urls)
for image_url in image_urls:
    print(image_url)
    print_url = url+image_url
    resp = requests.get(print_url)
    if resp.status_code == 200:
        with open(image_url, "wb") as file:
            file.write(resp.content)